package com.healthybear.demo.languagechange

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import androidx.activity.enableEdgeToEdge
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

/**
 * MainActivity serves as the entry point for the Multi-Language Switcher demo.
 * It provides navigation to three different implementation methods for language switching.
 * 
 * Requirements: 1.1, 1.2
 */
class MainActivity : BaseActivity() {
    
    companion object {
        const val EXTRA_IMPLEMENTATION_TYPE = "implementation_type"
    }
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        
        setupButtonClickHandlers()
    }
    
    override fun getImplementationType(): LanguageUtils.ImplementationType {
        // MainActivity doesn't have a specific implementation type
        return LanguageUtils.getRecommendedImplementationType()
    }
    
    /**
     * Set up click handlers for the three implementation method buttons
     * Requirement 1.1: Display three buttons representing different language switching implementation methods
     * Requirement 1.2: Navigate to the corresponding implementation activity when user selects a method
     */
    private fun setupButtonClickHandlers() {
        findViewById<Button>(R.id.btnMethod1).setOnClickListener {
            navigateToImplementation(LanguageUtils.ImplementationType.APP_COMPAT_DELEGATE)
        }
        
        findViewById<Button>(R.id.btnMethod2).setOnClickListener {
            navigateToImplementation(LanguageUtils.ImplementationType.CONFIGURATION_UPDATE)
        }
        
        findViewById<Button>(R.id.btnMethod3).setOnClickListener {
            navigateToImplementation(LanguageUtils.ImplementationType.SYSTEM_SETTINGS)
        }
    }
    
    /**
     * Navigate to the appropriate implementation activity based on the selected method
     * Includes proper activity transitions and intent extras for implementation type
     */
    private fun navigateToImplementation(implementationType: LanguageUtils.ImplementationType) {
        val targetActivity = when (implementationType) {
            LanguageUtils.ImplementationType.APP_COMPAT_DELEGATE -> Implementation1Activity::class.java
            LanguageUtils.ImplementationType.CONFIGURATION_UPDATE -> Implementation2Activity::class.java
            LanguageUtils.ImplementationType.SYSTEM_SETTINGS -> Implementation3Activity::class.java
        }
        
        val intent = Intent(this, targetActivity).apply {
            putExtra(EXTRA_IMPLEMENTATION_TYPE, implementationType.name)
        }
        
        startActivity(intent)
        
        // Add proper activity transition animation
        overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right)
    }
}